Ed Mastery: the Standard Unix Text Editor by Michael W Lucas

Ed Mastery: the Standard Unix Text Editor by Michael W Lucas

Author:Michael W Lucas [Lucas, Michael W]
Language: eng
Format: epub
Tags: nonfiction
Publisher: Tilted Windmill Press
Published: 2018-03-17T16:00:00+00:00


Running Commands on Searches

Commands to print the matching lines aren’t the only things you can do with searches. You can give the search any command other than a search command (g, G, v, or V).

An easy example is deleting matches. The d command deletes the current address. Here I strip away all lines that match the string “re.”

*g/re/d

Your buffer just shrank. If you’re following along at home, undo this before the next example.

Say you want to move lines that match the regular expression to the end of the buffer. Use the m command, with the $ destination address that matches the end of the file.

*g/re/m$

What does this give us?

*,n

1 the

2 their

3 then

4 Them

5 2

6 3weasels

7 /the/

8 pet rats

9 [pedicular]

10 hamster5

11 there

12 they're

13 thereafter

14 4 theremin

Ed moved through the buffer. Every time it found a match, it moved that line to the end of the file. You just automatically re-ordered your buffer! Doing so with a simple regex like this looks trivial, but when you build more complicated regexes you’ll find it useful.

Suppose you wanted to move everything that matches to the beginning of the file. The command differs by only the destination address, but the results look far different.

*g/re/m0

*,n

1 4 theremin

2 thereafter

3 they're

4 there

5 the

6 their

7 then

8 Them

9 2

10 3weasels

11 /the/

14 hamster5

The words that match our regular expression are at the top of the file, but their ordering has reversed. What was line 11 is now line 1, line 10 is now 2, and so on. In doing the global search, ed processes each line in order. Lines matching the regex get moved up to address zero. Line 5 matched, and got moved to zero. Line 6 then matched, and got moved to zero. Moving lines to the top of the stack—er, buffer—one at a time reverses their order. The same thing happens if you move lines to any address other than $, such as an address in the middle of the file.

Avoiding this reversal requires interactive editing with a regex.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(73907)
What's Done in Darkness by Kayla Perrin(26957)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20852)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20606)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20535)
The Fifty Shades Trilogy & Grey by E L James(19454)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19376)
Shot Through the Heart by Mercy Celeste(19236)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17384)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17351)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17179)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(17093)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16709)
The Subtle Art of Not Giving a F*ck by Mark Manson(14823)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14439)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(14211)
Cozy crochet hats: 7 Stylish and Beginner-Friendly Patterns from Baby Beanies to Trendy Bucket Hats by Vanilla Lazy(13491)
Scorched Earth by Nick Kyme(13092)
Reichel W. Numerical methods for Electrical Engineering, Meteorology,...2022 by Unknown(12974)
Drei Generationen auf dem Jakobsweg by Stein Pia(11254)